/*
 * Author: Minh-Tuan Ta
 * Date: 11/6/11
 * Class: ContentDB
 * This class used to access the data from Content table
 */
package data;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.sql.*;
import beans.*;

public class ContentDB extends DB {
	/*
	 * Author: Minh-Tuan Ta
	 * Date: 11/7/11
	 * Method: getAllContent
	 * This method will get all the content in the database
	 */
	public static synchronized ArrayList<Content> getAllContent()
	{
		Connection conn = null;
		ArrayList<Content> allContent = new ArrayList<Content>();
		PreparedStatement statement = null;
		String sql = "SELECT contentid, userid, contenttitle, contenttypeid, content" +
					 ",datecreated, extra, status\n" +
					 "FROM content";
		
		try
		{
			conn = getConnection();
			statement = conn.prepareStatement(sql);
			ResultSet rs = statement.executeQuery();
			
			while (rs.next())
			{
				Content content = new Content();
				setContent(content, rs);
				
				allContent.add(content);
			}
			
			rs.close();
			statement.close();
			conn.close();
		}
		catch (SQLException ex)
		{
			System.out.println("Error: " + ex);
			System.out.println("Query: " + statement.toString());
		}
		
		return allContent;
	}
	
	/*
	 * Author: Minh-Tuan Ta
	 * Date: 11/7/11
	 * Method: getContent
	 * This method will get a content giving the specific content id
	 */
	public static synchronized Content getContent(int contentid)
	{
		Connection conn = null;
		Content content = null;
		PreparedStatement statement = null;
		String sql = "SELECT contentid, userid, contenttitle, contenttypeid, content" +
					 ",datecreated, extra, status\n" +
					 "FROM content\n" +
					 "WHERE contentid = ?";
		
		try
		{
			conn = getConnection();
			statement = conn.prepareStatement(sql);
			statement.setInt(1, contentid);
			ResultSet rs = statement.executeQuery();
			
			if (rs.next())
			{
				content = new Content();
				setContent(content, rs);
			}
			
			rs.close();
			statement.close();
			conn.close();
		}
		catch (SQLException ex)
		{
			System.out.println("Error: " + ex);
			System.out.println("Query: " + statement.toString());
		}
		
		return content;
	}
	
	/*
	 * Author: Minh-Tuan Ta
	 * Date: 11/7/11
	 * Method: getContent
	 * This method will get a content giving the specific content id
	 */
	public static synchronized int getContentStatus(int contentid)
	{
		Connection conn = null;
		Content content = null;
		PreparedStatement statement = null;
		String sql = "SELECT status\n" +
					 "FROM content\n" +
					 "WHERE contentid = ?";
		
		try
		{
			conn = getConnection();
			statement = conn.prepareStatement(sql);
			statement.setInt(1, contentid);
			ResultSet rs = statement.executeQuery();
			
			if (rs.next())
			{
				content = new Content();
				setContent(content, rs);
			}
			
			rs.close();
			statement.close();
			conn.close();
		}
		catch (SQLException ex)
		{
			System.out.println("Error: " + ex);
			System.out.println("Query: " + statement.toString());
		}
		
		return content.getStatus();
	}
	
	/*
	 * Author: Minh-Tuan Ta
	 * Date: 11/7/11
	 * Method: getAllContentOfContenttype
	 * This method will get content of a specific type
	 */
	public static synchronized ArrayList<Content> getAllContentOfContenttype(int contenttypeid)
	{
		Connection conn = null;
		ArrayList<Content> allContent = new ArrayList<Content>();
		PreparedStatement statement = null;
		String sql = "SELECT contentid, userid, contenttitle, contenttypeid, content" +
					 ",datecreated, extra, status\n" +
					 "FROM content\n" +
					 "WHERE contenttypeid = ?";
		
		try
		{
			conn = getConnection();
			statement = conn.prepareStatement(sql);
			statement.setInt(1, contenttypeid);
			ResultSet rs = statement.executeQuery();
			
			while (rs.next())
			{
				Content content = new Content();
				setContent(content, rs);
				
				allContent.add(content);
			}
			
			rs.close();
			statement.close();
			conn.close();
		}
		catch (SQLException ex)
		{
			System.out.println("Error: " + ex);
			System.out.println("Query: " + statement.toString());
		}
		
		return allContent;
	}
	
	/*
	 * Author: Minh-Tuan Ta
	 * Date: 11/7/11
	 * Method: getAllContentOfUser
	 * This method will get content of a specific user
	 */
	public static synchronized ArrayList<Content> getAllContentOfUser(int userid)
	{
		Connection conn = null;
		ArrayList<Content> allContent = new ArrayList<Content>();
		PreparedStatement statement = null;
		String sql = "SELECT contentid, userid, contenttitle, contenttypeid, content" +
					 ",datecreated, extra, status\n" +
					 "FROM content\n" +
					 "WHERE userid = ?";
		
		try
		{
			conn = getConnection();
			statement = conn.prepareStatement(sql);
			statement.setInt(1, userid);
			ResultSet rs = statement.executeQuery();
			
			while (rs.next())
			{
				Content content = new Content();
				setContent(content, rs);
				
				allContent.add(content);
			}
			
			rs.close();
			statement.close();
			conn.close();
		}
		catch (SQLException ex)
		{
			System.out.println("Error: " + ex);
			System.out.println("Query: " + statement.toString());
		}
		
		return allContent;
	}
	
	/*
	 * Author: Minh-Tuan Ta
	 * Date: 11/7/11
	 * Method: getContentOfUserAndType
	 * This method will get content of a specific user with a specific type
	 */
	public static synchronized ArrayList<Content> getContentsOfUserAndType(int userid, int contenttypeid)
	{
		Connection conn = null;
		ArrayList<Content> allContent = new ArrayList<Content>();
		PreparedStatement statement = null;
		String sql = "SELECT contentid, userid, contenttitle, contenttypeid, content" +
					 ",datecreated, extra, status\n" +
					 "FROM content\n" +
					 "WHERE userid = ? AND contenttypeid = ?\n" +
					 "ORDER BY contentid DESC";
		
		try
		{
			conn = getConnection();
			statement = conn.prepareStatement(sql);
			statement.setInt(1, userid);
			statement.setInt(2, contenttypeid);
			ResultSet rs = statement.executeQuery();
			
			while (rs.next())
			{
				Content content = new Content();
				setContent(content, rs);
				
				allContent.add(content);
			}
			
			rs.close();
			statement.close();
			conn.close();
		}
		catch (SQLException ex)
		{
			System.out.println("Error: " + ex);
			System.out.println("Query: " + statement.toString());
		}
		
		return allContent;
	}
	
	public static synchronized ArrayList<Content> getContentsOfUserAndTypeAndStatus(int userid, int contenttypeid, int status)
	{
		Connection conn = null;
		ArrayList<Content> allContent = new ArrayList<Content>();
		PreparedStatement statement = null;
		String sql = "SELECT contentid, userid, contenttitle, contenttypeid, content" +
					 ",datecreated, extra, status\n" +
					 "FROM content\n" +
					 "WHERE userid = ? AND contenttypeid = ? AND status = ?\n" +
					 "ORDER BY contentid DESC";
		
		try
		{
			conn = getConnection();
			statement = conn.prepareStatement(sql);
			statement.setInt(1, userid);
			statement.setInt(2, contenttypeid);
			statement.setInt(3, status);
			ResultSet rs = statement.executeQuery();
			
			while (rs.next())
			{
				Content content = new Content();
				setContent(content, rs);
				
				allContent.add(content);
			}
			
			rs.close();
			statement.close();
			conn.close();
		}
		catch (SQLException ex)
		{
			System.out.println("Error: " + ex);
			System.out.println("Query: " + statement.toString());
		}
		
		return allContent;
	}
	
	public static synchronized ArrayList<Content> getContentOfUserAndTypeAndStatuses(int userID, int contenttypeid, ArrayList<Integer> statuses)
	{
		Connection conn = null;
		ArrayList<Content> allContent = new ArrayList<Content>();
		PreparedStatement statement = null;
		String sql = "SELECT contentid, userid, contenttitle, contenttypeid, content" +
					 ",datecreated, extra, status\n" +
					 "FROM content\n" +
					 "WHERE userID = ? AND contenttypeid = ? AND ";
					 
		
		try
		{
			conn = getConnection();
			if (statuses.size() > 0)
			{
				sql += "(status = " + statuses.get(0);
			}
			
			for (int i = 1; i < statuses.size(); i++)
			{
				sql += " OR status = " + statuses.get(i); 
			}
			
			if (statuses.size() > 0)
				sql += ")";
			
			sql += "\n";
			sql += "ORDER BY contentid DESC";
			statement = conn.prepareStatement(sql);
			statement.setInt(1, userID);
			statement.setInt(2, contenttypeid);
			
			ResultSet rs = statement.executeQuery();
			
			while (rs.next())
			{
				Content content = new Content();
				setContent(content, rs);
				
				allContent.add(content);
			}
			
			rs.close();
			statement.close();
			conn.close();
		}
		catch (SQLException ex)
		{
			System.out.println("Error: " + ex);
			System.out.println("Query: " + statement.toString());
		}
		
		return allContent;
	}
	
	public static synchronized ArrayList<Content> getContentOfUserAndTypeAndStatus(int userID, int contenttypeid, String status)
	{
		Connection conn = null;
		ArrayList<Content> allContent = new ArrayList<Content>();
		PreparedStatement statement = null;
		String sql = "SELECT contentid, userid, contenttitle, contenttypeid, content" +
					 ",datecreated, extra, status\n" +
					 "FROM content\n" +
					 "WHERE userID = ? AND contenttypeid = ? AND ";
					 
		
		try
		{
			conn = getConnection();
			sql += status;
			
			sql += "\n";
			sql += "ORDER BY contentid DESC";
			statement = conn.prepareStatement(sql);
			statement.setInt(1, userID);
			statement.setInt(2, contenttypeid);
			
			ResultSet rs = statement.executeQuery();
			
			while (rs.next())
			{
				Content content = new Content();
				setContent(content, rs);
				
				allContent.add(content);
			}
			
			rs.close();
			statement.close();
			conn.close();
		}
		catch (SQLException ex)
		{
			System.out.println("Error: " + ex);
			System.out.println("Query: " + statement.toString());
		}
		
		return allContent;
	}
	
	/*
	 * Author: Minh-Tuan Ta
	 * Date: 11/7/11
	 * Method: getContentOfExtraAndType
	 * This method will get content of a specific extra field with a specific type
	 */
	public static synchronized ArrayList<Content> getContentOfExtraAndType(int extra, int contenttypeid)
	{
		Connection conn = null;
		ArrayList<Content> allContent = new ArrayList<Content>();
		PreparedStatement statement = null;
		String sql = "SELECT contentid, userid, contenttitle, contenttypeid, content" +
					 ",datecreated, extra, status\n" +
					 "FROM content\n" +
					 "WHERE extra = ? AND contenttypeid = ?\n" +
					 "ORDER BY contentid DESC";
		
		try
		{
			conn = getConnection();
			statement = conn.prepareStatement(sql);
			statement.setInt(1, extra);
			statement.setInt(2, contenttypeid);
			ResultSet rs = statement.executeQuery();
			
			while (rs.next())
			{
				Content content = new Content();
				setContent(content, rs);
				
				allContent.add(content);
			}
			
			rs.close();
			statement.close();
			conn.close();
		}
		catch (SQLException ex)
		{
			System.out.println("Error: " + ex);
			System.out.println("Query: " + statement.toString());
		}
		
		return allContent;
	}
	
	/*
	 * Author: Minh-Tuan Ta
	 * Date: 11/7/11
	 * Method: getContentOfExtraAndTypeAndStatus
	 * 
	 */
	public static synchronized ArrayList<Content> getContentOfExtraAndTypeAndStatus(int extra, int contenttypeid, int status)
	{
		Connection conn = null;
		ArrayList<Content> allContent = new ArrayList<Content>();
		PreparedStatement statement = null;
		String sql = "SELECT contentid, userid, contenttitle, contenttypeid, content" +
					 ",datecreated, extra, status\n" +
					 "FROM content\n" +
					 "WHERE extra = ? AND contenttypeid = ? AND status=?\n" +
					 "ORDER BY contentid DESC";
		
		try
		{
			conn = getConnection();
			statement = conn.prepareStatement(sql);
			statement.setInt(1, extra);
			statement.setInt(2, contenttypeid);
			statement.setInt(3, status);
			ResultSet rs = statement.executeQuery();
			
			while (rs.next())
			{
				Content content = new Content();
				setContent(content, rs);
				
				allContent.add(content);
			}
			
			rs.close();
			statement.close();
			conn.close();
		}
		catch (SQLException ex)
		{
			System.out.println("Error: " + ex);
			System.out.println("Query: " + statement.toString());
		}
		
		return allContent;
	}
	
	public static synchronized ArrayList<Content> getContentOfExtraAndTypeAndStatuses(int extra, int contenttypeid, ArrayList<Integer> statuses)
	{
		Connection conn = null;
		ArrayList<Content> allContent = new ArrayList<Content>();
		PreparedStatement statement = null;
		String sql = "SELECT contentid, userid, contenttitle, contenttypeid, content" +
					 ",datecreated, extra, status\n" +
					 "FROM content\n" +
					 "WHERE extra = ? AND contenttypeid = ? AND ";
					 
		
		try
		{
			conn = getConnection();
			if (statuses.size() > 0)
			{
				sql += "(status = " + statuses.get(0);
			}
			
			for (int i = 1; i < statuses.size(); i++)
			{
				sql += " OR status = " + statuses.get(i); 
			}
			
			if (statuses.size() > 0)
				sql += ")";
			
			sql += "\n";
			sql += "ORDER BY contentid DESC";
			statement = conn.prepareStatement(sql);
			statement.setInt(1, extra);
			statement.setInt(2, contenttypeid);
			
			ResultSet rs = statement.executeQuery();
			
			while (rs.next())
			{
				Content content = new Content();
				setContent(content, rs);
				
				allContent.add(content);
			}
			
			rs.close();
			statement.close();
			conn.close();
		}
		catch (SQLException ex)
		{
			System.out.println("Error: " + ex);
			System.out.println("Query: " + statement.toString());
		}
		
		return allContent;
	}
	
	public static synchronized ArrayList<Content> getContentOfExtraAndTypeAndStatus(int extra, int contenttypeid, String status)
	{
		Connection conn = null;
		ArrayList<Content> allContent = new ArrayList<Content>();
		PreparedStatement statement = null;
		String sql = "SELECT contentid, userid, contenttitle, contenttypeid, content" +
					 ",datecreated, extra, status\n" +
					 "FROM content\n" +
					 "WHERE extra = ? AND contenttypeid = ? AND ";
					 
		
		try
		{
			conn = getConnection();
			sql += status;
			
			sql += "\n";
			sql += "ORDER BY contentid DESC";
			statement = conn.prepareStatement(sql);
			statement.setInt(1, extra);
			statement.setInt(2, contenttypeid);
			
			ResultSet rs = statement.executeQuery();
			
			while (rs.next())
			{
				Content content = new Content();
				setContent(content, rs);
				
				allContent.add(content);
			}
			
			rs.close();
			statement.close();
			conn.close();
		}
		catch (SQLException ex)
		{
			System.out.println("Error: " + ex);
			System.out.println("Query: " + statement.toString());
		}
		
		return allContent;
	}
	
	public static synchronized ArrayList<Content> getFriendsUpdates(int userid)
	{
		Connection conn = null;
		ArrayList<Content> allContent = new ArrayList<Content>();
		PreparedStatement statement = null;
		String sql = "SELECT contentid, userid, contenttitle, contenttypeid, content" +
					 ",datecreated, extra, status\n" +
					 "FROM content\n" +
					 "WHERE userid IN (0 ";;
		
		try
		{
			conn = getConnection();
			ArrayList<User> friends = FriendDB.getFriends(userid);
			
			for (int i = 0; i < friends.size(); i++)
			{
				sql += ", " + friends.get(i).getUserID(); 
			}
			
			sql += ")\n";
			sql += "ORDER BY contentid DESC";
			
			statement = conn.prepareStatement(sql);
			ResultSet rs = statement.executeQuery();
			
			while (rs.next())
			{
				Content content = new Content();
				setContent(content, rs);
				
				allContent.add(content);
			}
			
			rs.close();
			statement.close();
			conn.close();
		}
		catch (SQLException ex)
		{
			System.out.println("Error: " + ex);
			System.out.println("Query: " + statement.toString());
		}
		
		return allContent;
	}
	
	/*
	 * Author: Minh-Tuan Ta
	 * Date: 11/7/11
	 * Method: addContent
	 * This method will add a new Content to the database
	 */
	public static synchronized int addContent(Content content)
	{
		Connection conn = null;
		int status = 0;
		PreparedStatement statement = null;
		String sql = "INSERT INTO content(userid, contenttypeid, content" +
					 ",datecreated, extra, status, contenttitle)\n" +
					 "VALUES(?, ?, ?, ?, ?, ?, ?)";

		try
		{
			conn = getConnection();
			statement = conn.prepareStatement(sql);
			statement.setInt(1, content.getUserID());
			statement.setInt(2, content.getContentTypeID());
			statement.setString(3, content.getContent());
			statement.setTimestamp(4, content.getDateCreated());
			statement.setInt(5, content.getExtra());
			statement.setInt(6, content.getStatus());
			statement.setString(7, content.getContentTitle());
			
			status = statement.executeUpdate();
			
			statement.close();
			
			statement = conn.prepareStatement("SELECT LAST_INSERT_ID()");
			
			ResultSet rs = statement.executeQuery();
			
			if (rs.next())
			{
				content.setContentID(rs.getInt(1));
			}
			
			statement.close();
			conn.close();
		}
		catch (SQLException ex)
		{
			System.out.println("Error: " + ex);
			System.out.println("Query: " + statement.toString());
		}
		
		return status;
	}
	
	/*
	 * Author: Minh-Tuan Ta
	 * Date: 11/7/11
	 * Method: updateContent
	 * This method will update a Content to the database
	 */
	public static synchronized int updateContent(Content content)
	{
		Connection conn = null;
		int status = 0;
		PreparedStatement statement = null;
		String sql = "UPDATE content SET\n" +
					 "userid = ?, contenttypeid = ?, content = ?" +
					 ",datecreated = ?, extra = ?, status = ?, contenttitle = ?\n" +
					 "WHERE contentid = ?";

		try
		{
			conn = getConnection();
			statement = conn.prepareStatement(sql);
			statement.setInt(1, content.getUserID());
			statement.setInt(2, content.getContentTypeID());
			statement.setString(3, content.getContent());
			statement.setTimestamp(4, content.getDateCreated());
			statement.setInt(5, content.getExtra());
			statement.setInt(6, content.getStatus());
			statement.setString(7, content.getContentTitle());
			statement.setInt(8, content.getContentID());
			
			status = statement.executeUpdate();
			
			statement.close();
			conn.close();
		}
		catch (SQLException ex)
		{
			System.out.println("Error: " + ex);
			System.out.println("Query: " + statement.toString());
		}
		
		return status;
	}
	
	/*
	 * Author: Minh-Tuan Ta
	 * Date: 11/7/11
	 * Method: deleteContent
	 * This method will delete a Content to the database
	 */
	public static synchronized int deleteContent(Content content)
	{
		int status = 0;
		PreparedStatement statement = null;
		Connection conn = null;
		String sql = "DELETE FROM content\n" +
				 "WHERE contentid = ?";

		try
		{
							
			//delete related rating first
			ArrayList<HelpfulRating> ratings = HelpFulRatingDB.getHelpfulRatingsOfContent(content.getContentID());
			
			for (int i = 0; i < ratings.size(); i++)
			{
				HelpFulRatingDB.deleteRating(ratings.get(i));
			}
			
			conn = getConnection();
			statement = conn.prepareStatement(sql);
			statement.setInt(1, content.getContentID());
			
			status = statement.executeUpdate();
			
			statement.close();
			conn.close();
		}
		catch (SQLException ex)
		{
			System.out.println("Error: " + ex);
			System.out.println("Query: " + statement.toString());
		}
		
		return status;
	}
	
	public static synchronized Comment convertContentToComment(Content content)
	{
		Comment comment = new Comment();
		
		comment.setContent(content.getContent());
		comment.setContentID(content.getContentID());
		comment.setContentTitle(content.getContentTitle());
		comment.setContentTypeID(content.getContentTypeID());
		comment.setDateCreated(content.getDateCreated());
		comment.setExtra(content.getExtra());
		comment.setStatus(content.getStatus());
		comment.setUserID(content.getUserID());
		comment.setNumHelpful(HelpFulRatingDB.getHelpfulRatingsOfContent(comment.getContentID()).size());
		comment.setNumNotHelpful(HelpFulRatingDB.getNotHelpfulRatingsOfContent(comment.getContentID()).size());
		comment.setUser(UserDB.getUser(comment.getUserID()));
		comment.setFormattedDateCreatedString(content.getFormattedDateCreatedString());
		
		return comment;
	}
	
	public static synchronized ArrayList<Comment> convertContentsToComments(ArrayList<Content> contents)
	{
		ArrayList<Comment> comments = new ArrayList<Comment>();
		
		for (int i = 0; i < contents.size(); i++)
		{
			comments.add(convertContentToComment(contents.get(i)));
		}
		
		return comments;
	}
	
	public static synchronized Post convertContentToPost(Content content)
	{
		Post post = new Post();
		
		post.setContent(content.getContent());
		post.setContentID(content.getContentID());
		post.setContentTitle(content.getContentTitle());
		post.setContentTypeID(content.getContentTypeID());
		post.setDateCreated(content.getDateCreated());
		post.setExtra(content.getExtra());
		post.setStatus(content.getStatus());
		post.setUserID(content.getUserID());
		post.setNumHelpful(HelpFulRatingDB.getHelpfulRatingsOfContent(post.getContentID()).size());
		post.setNumNotHelpful(HelpFulRatingDB.getNotHelpfulRatingsOfContent(post.getContentID()).size());
		post.setComments(CommentDB.getCommentsForContent(post.getContentID()));
		post.setFormattedDateCreatedString(content.getFormattedDateCreatedString());
		
		return post;
	}
	
	public static synchronized ArrayList<Post> convertContentsToPosts(ArrayList<Content> contents)
	{
		ArrayList<Post> posts = new ArrayList<Post>();
		
		for (int i = 0; i < contents.size(); i++)
		{
			posts.add(convertContentToPost(contents.get(i)));
		}
		
		return posts;
	}
	
	public static synchronized Photo convertContentToPhoto(Content content)
	{
		Photo photo = new Photo();
		
		photo.setContent(content.getContent());
		photo.setContentID(content.getContentID());
		photo.setContentTitle(content.getContentTitle());
		photo.setContentTypeID(content.getContentTypeID());
		photo.setDateCreated(content.getDateCreated());
		photo.setExtra(content.getExtra());
		photo.setStatus(content.getStatus());
		photo.setUserID(content.getUserID());
		photo.setPhotoPath((ResourceDB.getResourceByContentID(content.getContentID())).getPath());
		photo.setFormattedDateCreatedString(content.getFormattedDateCreatedString());
		
		return photo;
	}
	
	public static synchronized ArrayList<Photo> convertContentsToPhotos(ArrayList<Content> contents)
	{
		ArrayList<Photo> photos = new ArrayList<Photo>();
		
		for (int i = 0; i < contents.size(); i++)
		{
			photos.add(convertContentToPhoto(contents.get(i)));
		}
		
		return photos;
	}
	
	public static synchronized Album convertContentToAlbum(Content content)
	{
		Album album = new Album();
		
		album.setContent(content.getContent());
		album.setContentID(content.getContentID());
		album.setContentTitle(content.getContentTitle());
		album.setContentTypeID(content.getContentTypeID());
		album.setDateCreated(content.getDateCreated());
		album.setExtra(content.getExtra());
		album.setStatus(content.getStatus());
		album.setUserID(content.getUserID());
		album.setFormattedDateCreatedString(content.getFormattedDateCreatedString());
		album.setPhotos(PhotoDB.getPhotosInAlbum(content.getContentID()));
		if (album.getPhotos().size() > 0)
		{
			album.setPhotoPath(album.getPhotos().get(0).getPhotoPath());
		}
		else
		{
			album.setPhotoPath("images/no-photo.jpg");
		}
		
		return album;
	}
	
	public static synchronized ArrayList<Album> convertContentsToAlbums(ArrayList<Content> contents)
	{
		ArrayList<Album> albums = new ArrayList<Album>();
		
		for (int i = 0; i < contents.size(); i++)
		{
			albums.add(convertContentToAlbum(contents.get(i)));
		}
		
		return albums;
	}
	
	public static synchronized Message convertContentToMessage(Content content)
	{
		Message message = new Message();
		
		message.setContent(content.getContent());
		message.setContentID(content.getContentID());
		message.setContentTitle(content.getContentTitle());
		message.setContentTypeID(content.getContentTypeID());
		message.setDateCreated(content.getDateCreated());
		message.setExtra(content.getExtra());
		message.setStatus(content.getStatus());
		message.setUserID(content.getUserID());
		message.setSender(UserDB.getUser(message.getUserID()));
		message.setReciever(UserDB.getUser(message.getExtra()));
		message.setFormattedDateCreatedString(content.getFormattedDateCreatedString());
		
		return message;
	}
	
	public static synchronized ArrayList<Message> convertContentsToMessages(ArrayList<Content> contents)
	{
		ArrayList<Message> messages = new ArrayList<Message>();
		
		for (int i = 0; i < contents.size(); i++)
			messages.add(convertContentToMessage(contents.get(i)));
		
		return messages;
	}
}
